//
//  HistoryDetail.m
//  Dormitory2404
//
//  Created by gleeman.G on 2017/12/25.
//  Copyright © 2017年 Hainan Suyun network technology co. LTD. All rights reserved.
//

#import "HistoryDetail.h"
#import "OrderCell.h"
#import "order.h"
#import "History.h"

@interface HistoryDetail ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation HistoryDetail

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"消费详情";
    
    [self tableViewSetting];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tableViewSetting{
    [self.view addSubview:self.tableView];
    self.tableView.dataSource = self;
    self.tableView.delegate =  self;
    self.tableView.tableFooterView = [[UIView alloc]init];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"OrderCell" bundle:nil] forCellReuseIdentifier:NSStringFromClass([OrderCell class])];
    
    self.tableView.tableFooterView = [[UIView alloc]init];
    
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    OrderCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([OrderCell class])];
    order * order = nil ;
    if (indexPath.row < self.dataArray.count) {
        order = self.dataArray[indexPath.row];
    }
    cell.nameLabel.text = order.name;
    cell.priceLabel.text = order.price;
    cell.contentLabel.text = order.content;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.f;
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        History *his = [HistoryList shareInstance].historyList[self.index];
        _dataArray = his.orderList;
    }
    return _dataArray;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
